package cn.stronglink.assetmanage.business.inspection.presenter;

import android.os.Bundle;

import java.util.List;
import java.util.Map;

import cn.stronglink.assetmanage.MainActivity;
import cn.stronglink.assetmanage.business.inspection.model.AlreadyPatrolModel;
import cn.stronglink.assetmanage.business.inspection.model.WaitPatrolModel;
import cn.stronglink.assetmanage.business.inspection.view.already.AlreadyPatrolView;
import cn.stronglink.assetmanage.business.inspection.view.wait.WaitPatrolView;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.Patrol;
import cn.stronglink.assetmanage.entity.PatrolDetail;
import cn.stronglink.assetmanage.entity.RepailDetail;
import cn.stronglink.assetmanage.entity.Repair;
import cn.stronglink.assetmanage.entity.SearchAsset;
import cn.stronglink.assetmanage.index.base.BasePresenter;
import cn.stronglink.assetmanage.index.entity.PromissionEntity;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * Created by zhengjinglan on 2018/6/18.
 */

public class AlreadyPatrolPresenter{
    private AlreadyPatrolModel alreadyPatrolModel;
    private AlreadyPatrolView alreadyPatrolView;
    //巡检表单列表
    private List<Patrol> patrolList;
    //盘点资产二级列表
    private Map<String, List<PatrolDetail>> itemDetailList;
    //选择的表单
    private Patrol patrol;

    public AlreadyPatrolPresenter(AlreadyPatrolModel alreadyPatrolModel,
                                  AlreadyPatrolView alreadyPatrolView) {
        this.alreadyPatrolModel = alreadyPatrolModel;
        this.alreadyPatrolView = alreadyPatrolView;
    }

    /**
     * 初始化已巡检表单列表
     */
    public void initInventoryListView() {
        patrolList = alreadyPatrolModel.getDataByOrderNoDistince();
        alreadyPatrolView.setListData(patrolList);
    }

    /**
     * 根据点击位置显示资产列表
     *
     * @param position
     */
    public void showOrderByPosition(int position) {

        // 显示盘点详情页面
        MainActivity activity = (MainActivity) this.alreadyPatrolView.getFragment().getActivity();
        PromissionEntity pe = new PromissionEntity();
        pe.setPosition(MainActivity.FRAGMENT_PATROL_DETAIL_ID);

        // 设置打开巡检详情后传递的参数
        patrol = patrolList.get(position);
        Bundle bundle = new Bundle();
        bundle.putSerializable(Constants.PATROL_DETAIL_NO, patrol.getId_());
        pe.setBundle(bundle);

        activity.onEventRegister(pe);

    }
    public void showDetailByPosition(String groupName, int childPosition) {
        PatrolDetail patrolDetail = itemDetailList.get(groupName).get(childPosition);
        alreadyPatrolView.showOrderDetail(patrolDetail);
    }

}
